﻿using System.Data.Entity;

namespace GuRenFang.Service.Entity
{
    public class SiteDb:DbContext
    {
        public SiteDb() : base("AncientLand")
        {
            
        }
        public DbSet<News> News { get; set; }

        public DbSet<Activities> Activities { get; set; }

        public DbSet<Messages> Messages { get; set; }

        public DbSet<Packages> Packages { get; set; }

        public DbSet<Photos> Photos { get; set; }

        public DbSet<ContentInfo> ContentInfos { get; set; }

        public DbSet<Category> Categorys { get; set; }
        public DbSet<WeddingCategory> WeddingCategorys { get; set; }
        public DbSet<PictorialCategory> PictorialCategorys { get; set; }

        public virtual void Commit()
        {
            base.SaveChanges();
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Photos>()
                  .Map<WeddingPhoto>(m => m.Requires("PhotosType").HasValue(1))
                  .Map<PictorialPhoto>(m => m.Requires("PhotosType").HasValue(2));  

            modelBuilder.Entity<Category>()
                  .Map<WeddingCategory>(m => m.Requires("CategoryType").HasValue(1))
                  .Map<PictorialCategory>(m => m.Requires("CategoryType").HasValue(2));

            modelBuilder.Entity<ContentInfo>()
                  .Map<TipsInfo>(m => m.Requires("InfoType").HasValue(2))
                  .Map<CompanyInfo>(m => m.Requires("InfoType").HasValue(1));  
        }
    }

    public class DbContextInitializer : DropCreateDatabaseIfModelChanges<SiteDb>
    {
        protected override void Seed(SiteDb context)
        {

        }
    }
}
